using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TMS.Application.Common.Interface;
using TMS.Application.RequestDto;
using TMS.Domain.Entity;

namespace TMS.Api.StaticClasses
{
    public class ClassData
    {

        public List<MajorDataDto> Class(IRepository<College> _College, IRepository<Major> _Major, IRepository<Class> _Class)
        {

            var colleges = _College.Table.ToList();

            var majors = _Major.Table.ToList();

            var classes = _Class.Table.ToList();

            List<MajorDataDto> list = new List<MajorDataDto>();

            foreach (var x in colleges)
            {

                List<ClassDataDto> list2 = new List<ClassDataDto>();

                var majorData = majors.Where(j => x.Id == j.CollegeId).Select(x => new { x.Id, x.CollegeId, x.MajorName }).ToList();

                foreach (var y in majorData)
                {


                    List<ClassDto> list3 = new List<ClassDto>();

                    var classData = classes.Where(x => x.MajorId == y.Id).Select(x => new { x.Id, x.MajorId, x.ClassName }).ToList();

                    foreach (var z in classData)
                    {


                        var data = new ClassDto
                        {

                            value = z.Id,

                            label = z.ClassName,

                            MajorId = z.MajorId

                        };

                        list3.Add(data);

                    }


                    var data2 = new ClassDataDto
                    {

                        value = y.Id,

                        label = y.MajorName,

                        CollegeId = y.CollegeId,

                        children=list3

                    };

                    list2.Add(data2);

                }

                var data3 = new  MajorDataDto{

                    value=x.Id,

                    label=x.CollegeName,

                    children=list2

                };


                list.Add(data3);

            }

            return list;

        }


    }
}